var myuserhost = "";
document.write( "<link rel='stylesheet' href='"+myuserhost+"css/user.css'></link>");
var layeruser='';
    layeruser+='<div class="layeruser">';
    //登录
    layeruser+='<div class="Popup login">';
    layeruser+='<div class="tile"> <div class="bt"><span class="on">登录</span> </div><div class="rit"><a onclick="openloginwx()">微信登录</a></div> </div>';
    layeruser+='<form class="item_ layui-form formbox">';
    layeruser+='<div class="layui-form-item inputline username">';
    layeruser+='<input type="text" name="username" placeholder="请输入用户名" class="layui-input" data-lab="name">';
    layeruser+='<div class="Tiptishi"> <p><span>请输入用户名，3-15个字符</span></p></div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item inputline password">';
    layeruser+='<input type="text" name="password" placeholder="请输入密码" class="layui-input" data-lab="password">';
    layeruser+='<div class="Tiptishi"> <p> <span>请输入密码，最少6-15个字符</span></p> </div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item inputline veCode">';
    layeruser+='<input type="text" name="veCode" placeholder="请输入的验证码" class="layui-input" data-lab="veCode">';
    layeruser+='<div class="veCodeinput">';
    layeruser+='<img id="reset-captcha-img" src="img/captcha.png" data-url="/index/captcha" alt="验证码" title="更换验证码">';
    layeruser+='</div>';
    layeruser+='<div class="Tiptishi"> <p> <span>输入的验证码不正确</span></p></div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item textline">';
    layeruser+='<input type="checkbox" name="automatic" lay-skin="primary" title="自动登录">';
    layeruser+='<div class="layui-word"><span onclick="openregister()">立即注册</span><i>|</i><span onclick="openReset()">找回密码</span></div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item btnbox">';
    layeruser+='<button type="button" class="layui-btn submitbtn" onclick="submit_login(this)">登录</button>';
    layeruser+='</div>';
    layeruser+=' </form>';
    layeruser+='</div>';
     // 微信登录
    layeruser+='<div class="Popup wxlogin">';
    layeruser+='<div class="tile"> <div class="bt"><span class="on">登录</span> </div><div class="rit"><a onclick="openlogin()">密码登录</a></div> </div>';
    layeruser+='<div class="item_ QRcode layui-form  ">';
    layeruser+='<div class="p bold">使用微信授权登录</div>';
    layeruser+='<div class="codeimg">';
    layeruser+='<img src="images/wx_img.png" alt="">';
    layeruser+='</div>';
    layeruser+='<button type="button" class="layui-btn submitbtn" onclick="openwxapp(this)">一键登录</button>';
    layeruser+='<div class="p layui-form-item">';
    layeruser+='<input type="checkbox" checked  disabled name="automatic" lay-skin="primary" title="授权登录即代表同意">';
    layeruser+='<a href="##">《服务协议和隐私政策》</a>';
    layeruser+='</div>';
    layeruser+='</div>';
    layeruser+='</div>';

    // 注册
    layeruser+='<div class="Popup register">';
    layeruser+='<div class="tile">';
    layeruser+='<div class="bt"><span class="on">注册</span></div>';
    layeruser+='<div class="rit">已有账号，<a onclick=" openlogin()">马上登录</a> </div>';
    layeruser+=' </div>';
    layeruser+='<div class="tabbox">';
    layeruser+='<form class="item_ layui-form formbox">';
    layeruser+='<div class="layui-form-item inputline iphone">';
    layeruser+='<input type="text" name="iphone" placeholder="请输入手机号" class="layui-input" data-lab="iphone">';
    layeruser+='<div class="Tiptishi"><p><span>请输入正确手机号</span></p></div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item inputline iphoneCode">';
    layeruser+='<input type="text" name="iphoneCode" placeholder="验证码" class="layui-input" data-lab="veCode">';
    layeruser+='<div class="code" onclick="get_findpwdsms(this)">发送验证码</div>';
    layeruser+='<div class="Tiptishi"> <p> <span>输入的手机短信验证码不正确</span></p></div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item inputline password">';
    layeruser+='<input type="password"  name="password" placeholder="请设置你的登录密码 6-15位字符" class="layui-input" data-lab="password">';
    layeruser+='<div class="Tiptishi"><p> <span>请输入密码，最少6-15个字符</span></p> </div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item inputline password">';
    layeruser+='<input type="password" name="password" placeholder="请再次输入你设置的登录密码" class="layui-input" data-lab="password2">';
    layeruser+='<div class="Tiptishi"><p> <span>2次密码不一致</span></p> </div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item inputline username">';
    layeruser+='<input type="text" name="username" placeholder="请设置昵称" class="layui-input" data-lab="name">';
    layeruser+='<div class="Tiptishi"><p><span>请输入用户名，3-15个字符</span></p></div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item textline">';
    layeruser+='<input type="checkbox" name="automatic2" checked lay-skin="primary" title="注册即代表您已同意">';
    layeruser+='<a href="##">《服务协议和隐私政策》</a>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item btnbox">';
    layeruser+='<button type="button" class="layui-btn submitbtn" onclick="submit_register(this)">注册</button>';
    layeruser+='</div>';
    layeruser+='</form>';
    layeruser+='</div>';
    layeruser+='</div>';
//   重置密码
    layeruser+='<div class="Popup Reset">';
    layeruser+='<div class="tile">';
    layeruser+='<div class="bt"><span class="on">重置密码</span></div>';
    layeruser+='<div class="rit">已有账号，<a onclick=" openlogin()">马上登录</a> </div>';
    layeruser+='</div>';
    layeruser+='<div class="tabbox">';
    layeruser+='<form class="item_ layui-form formbox">';
    layeruser+='<div class="layui-form-item inputline iphone">';
    layeruser+='<input type="text" name="iphone" placeholder="请输入手机号" class="layui-input" data-lab="iphone">';
    layeruser+='<div class="Tiptishi"><p><span>请输入正确手机号</span></p></div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item inputline iphoneCode">';
    layeruser+='<input type="text" name="iphoneCode" placeholder="验证码" class="layui-input" data-lab="veCode">';
    layeruser+='<div class="code" onclick="get_findpwdsms(this)">发送验证码</div>';
    layeruser+='<div class="Tiptishi"> <p> <span>输入的手机短信验证码不正确</span></p></div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item inputline password">';
    layeruser+='<input type="password"  name="password" placeholder="请设置你的登录密码 6-15位字符" class="layui-input" data-lab="password">';
    layeruser+='<div class="Tiptishi"> <p> <span>请输入密码，最少6-15个字符</span></p></div>';
    layeruser+='</div>';
    layeruser+='<div class="layui-form-item inputline password">';
    layeruser+='<input type="password" name="password" placeholder="请再次输入你设置的登录密码" class="layui-input" data-lab="password2">';
    layeruser+='<div class="Tiptishi"> <p> <span>2次密码不一致</span></p> </div>';
    layeruser+='</div>';
    layeruser+='<div class="Tiptishi"> <p> <span>重置密码失败</span></p> </div>';
    layeruser+='<div class="layui-form-item btnbox">';
    layeruser+='<button type="button" class="layui-btn submitbtn" onclick="submit_Reset(this)">重置</button>';
    layeruser+='</div>';
    layeruser+='</form>';
    layeruser+='</div>';
    layeruser+='</div>';
    layeruser+='</div>';
    $('body').append(layeruser)
$(".layeruser .Popup .tile .bt span").click(function (index) {
    $(this).addClass("on").siblings().removeClass("on");
    var box = $(this).parents(".Popup").find(".tabbox .item_");
    var i = $(this).index()
    console.log(i)
    box.eq(i).show().siblings().hide()
})
// 显示登录
function openlogin() {
    layer.closeAll();
    var login = layer.open({
        type: 1,
        title: false,
        closeBtn: 1,
        shadeClose: false,
        content: $('.layeruser .login')
    });
}
// 显示微信登录
function openloginwx() {
    layer.closeAll();
    var login = layer.open({
        type: 1,
        title: false,
        closeBtn: 1,
        shadeClose: false,
        content: $('.layeruser .wxlogin')
    });
}
// openlogin()  调用登录
// 显示注册
function openregister() {
    layer.closeAll();
    var login = layer.open({
        type: 1,
        title: false,
        closeBtn: 1,
        shadeClose: false,
        content: $('.layeruser .register')
    });
}
// openregister()  调用注册
// 显示重置密码
function openReset() {
    layer.closeAll();
    var login = layer.open({
        type: 1,
        title: false,
        closeBtn: 1,
        shadeClose: false,
        content: $('.layeruser .Reset')
    });
}
// openReset()  调用重置密码
// 验证
function verification(that) {
    function show(obj_, lab) {
        if (lab) {
            obj_.addClass('focus');
            obj_.find(".Tiptishi p").show();
        } else {
            obj_.removeClass('focus');
            obj_.find(".Tiptishi p").hide();
            var labe = obj_.find(".Tiptishi p").is(":visible");
        }
    }
    var val = that.find(".inputline .layui-input[name='password']").val();
    var val2 = that.find(".inputline .layui-input[name='password2']").val();

    that.find(".inputline").each(function () {
        var this_ = $(this).find(".layui-input");
        if (this_.val() == '') {
            show($(this), true);
            this_.focus();
            return false;
        } else {
            show($(this), true);
            this_.focus();
            //  验证用户名
            if (/^[a-zA-Z][a-zA-Z0-9_]{4,11}[a-zA-Z0-9]$/.test(this_.val()) && this_.attr("data-lab") == 'name') {
                show($(this), false);
            }
            //  验证密码
            if (/^.{6,15}$/.test(this_.val()) && this_.attr("data-lab") == 'password') {
                show($(this), false);
            }
            //  验证密码重复密码
            if (this_.attr("data-lab") == 'password2' && val == val2) {
                show($(this), false);
            }
            //  验证手机号
            if (/^[1][3,4,5,7,8][0-9]{9}$/.test(this_.val()) && this_.attr("data-lab") == 'iphone') {
                show($(this), false);
            }
            // 验证码的判断
            if (this_.attr("data-lab") == 'veCode') {
                show($(this), false);
            }
        }
    });
}
// 点击登录
function submit_login(obj) {
    var that = $(obj).parents(".formbox");
    verification(that);
    var username = that.find(".inputline .layui-input[name='username']").val();
    var password = that.find(".inputline .layui-input[name='password']").val();
    var code = that.find(".inputline .layui-input[name='veCode']").val();
    var check = 0;
    if ($("input[name='automatic']").is(':checked')) {
        check = 1;
    }
    if (!that.find(".inputline .Tiptishi p").is(":visible")) {
        var index = layer.msg('登录中...', { time: 10 * 1000 });
        $.ajax({
            url: "/index/login",
            type: "post",
            data: { username: username, password: password, rememberMe: check, code: code },
            dataType: "json",
            success: function (res) {
                layer.close(index);
                if (res.code == 1) {
                    layer.msg(res.message);
                    window.location.reload();
                } else {
                    layer.msg(res.message);
                    if (res.codeshow == 1) {
                        $(".logincaptcha").show();
                        logincaptcha();
                    }
                }
            },
        });
    }
}
// 点击注册
function submit_register(obj) {
    if (!$("input[name='automatic2']").is(':checked')) {
        layer.msg('请勾选服务协议和隐私政策');
        return false;
    }
    var that = $(obj).parents(".formbox");
    verification(that);
    var iphone = that.find(".inputline .layui-input[name='iphone']").val();
    var username = that.find(".inputline .layui-input[name='username']").val();
    var password = that.find(".inputline .layui-input[name='password2']").val();
    var iphoneCode = that.find(".inputline .layui-input[name='iphoneCode']").val();
    if (!that.find(".inputline .Tiptishi p").is(":visible")) {
        $.ajax({
            url: "/index/register",
            type: "post",
            data: { iphone: iphone, username: username, password: password, code: iphoneCode },
            dataType: "json",
            success: function (res) {
                if (res.code == 1) {
                    layer.msg(res.message);
                    if (res.login == 1) {
                        setTimeout("window.location.reload()", 3000);
                    } else {
                        openlogin();
                    }
                } else {
                    layer.msg(res.message);
                    regcaptcha();
                }
            },
            erroe: function () {
                layer.msg("网络异常");
            }
        });
    }
}
// 重置密码
function submit_Reset(obj) {
    if (!$("input[name='automatic2']").is(':checked')) {
        layer.msg('请勾选服务协议和隐私政策');
        return false;
    }
    var that = $(obj).parents(".formbox");
    verification(that);
    var iphone = that.find(".inputline .layui-input[name='iphone']").val();
    var password = that.find(".inputline .layui-input[name='password2']").val();
    var iphoneCode = that.find(".inputline .layui-input[name='iphoneCode']").val();
    if (!that.find(".inputline .Tiptishi p").is(":visible")) {
        $.ajax({
            url: "/index/register",
            type: "post",
            data: { iphone: iphone, password: password, code: iphoneCode },
            dataType: "json",
            success: function (res) {
                if (res.code == 1) {
                    layer.msg(res.message);
                    if (res.login == 1) {
                        setTimeout("window.location.reload()", 3000);
                    } else {
                        openlogin();
                    }
                } else {
                    layer.msg(res.message);
                    regcaptcha();
                }
            },
            erroe: function () {
                layer.msg("网络异常");
            }
        });
    }
}
// 获取手机验证码
function get_findpwdsms(obj) {
    if ($(obj).hasClass("time_bg")) {
        return false;
    }
    $(obj).addClass('time_bg');
    var time = 60;
    var time60 = setInterval(function () {
        time = time - 1
        if (time == 0) {
            time = 0
        }
        $(obj).html('(' + time + 'S)')
        if (time == 0) {
            clearInterval(time60)
            $(obj).removeClass('time_bg');
            $(obj).text('发送验证码');
        }
    }, 1000);
    var url = "/api/sendsms";
    var phone = $(obj).parents('.tabbox').find(".inputline .layui-input[name='iphone']").val();
    // $.ajax({
    //     url: url,
    //     async:false,
    //     type: "POST",
    //     data:{mobile:phone },
    //     dataType:'json',
    //     success: function(data){
    //         if(data.code == 1){
    //             layer.msg('验证码发送成功，请注意查收');
    //             alert("");
    //         }else{
    //             layer.msg('验证码发送失败');
    //         }
    //     },
    //     complete: function(){
    //         clearInterval(time60);
    //         $(obj).removeClass('time_bg'); 
    //         $(obj).text('发送验证码'); 
    //     }
    // });
}

// 预约
function submityuyue(obj){
    if (!$("input[name='automatic3']").is(':checked')) {
        layer.msg('请勾选服务协议和隐私政策');
        return false;
    }
    var that = $(obj).parents(".formbox");
    verification(that);
    var iphone = that.find(".inputline .layui-input[name='iphone']").val();
    var iphoneCode = that.find(".inputline .layui-input[name='iphoneCode']").val();
    if (!that.find(".inputline .Tiptishi p").is(":visible")) {
    openlayertishi('预约新游','预约成功！,到时你将收到我们的短信提醒。')  //参数1是标题， 参数是介绍文字 换行用逗号隔开。
        $.ajax({
            url: "/index/register",
            type: "post",
            data: { iphone: iphone,  code: iphoneCode },
            dataType: "json",
            success: function (res) {
                if (res.code == 1) {
                   
                } else {
                    layer.msg(res.message);
                    regcaptcha();
                }
            },
            erroe: function () {
                layer.msg("网络异常");
            }
        });
    }
}
 
// 打开微信app
function openwxapp(){
    layer.msg('打开微信')
}
